package com.zlp.netty.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;
import java.util.Scanner;

/**
 * @author: zhulaiping
 * @time: 2022/8/18 17:23
 */
public class NIOClientDemo1 {

    public static void main(String[] args) {
        try (SocketChannel s = SocketChannel.open()) {
            s.connect(new InetSocketAddress("localhost",8080));
            Scanner scanner = new Scanner(System.in);
            s.write(Charset.defaultCharset().encode("hello11111\nworld\n"));
            while (true){
                System.out.println("请输入发送信息：");
                String msg = scanner.nextLine();
                if(msg.equals("exit")) break;
                s.write(Charset.defaultCharset().encode(msg));
            }
            s.close();
            System.out.println("waiting.....");
        } catch (IOException e) {
        }
    }
}
